#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h> //action所用到的信息格式
#include <actionlib/client/simple_action_client.h> //简单的action客户端

typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient; //对象类型《消息类型》

int main(int argc, char** argv)
{
    ros::init(argc, argv, "nav_client");

    MoveBaseClient ac("move_base" ,true); //构建action客户端"move_base"是连接的节点，ture是自动调用slin函数

    while (!ac.waitForServer(ros::Duration(5.0)))
    {
        ROS_INFO("waiting for the move_base action server to come up"); //等待5s判断move base节点是否启动
    }

    move_base_msgs::MoveBaseGoal goal; //导航消息包

    goal.target_pose.header.frame_id = "map"; //确定坐标系为map
    goal.target_pose.header.stamp = ros::Time::now(); //打上时间辍

    goal.target_pose.pose.position.x = -3.0; //建立的坐标系以map的坐标系为方向，slam开始的点为原点
    goal.target_pose.pose.position.y = 2.0; //表示到达原点位置的-3，2点的位置，单位为米
    goal.target_pose.pose.orientation.w = 1.0;//姿态

    ROS_INFO("Sending goal");
    ac.sendGoal(goal);//设置发送的信息

    ac.waitForResult();//在没有到达目标位置的时候代码会在这里卡住

    if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) //判断是否到到位置
        ROS_INFO("Mission complete!");
    else
        ROS_INFO("Mission failed ...");
    
    return 0; 
}